<?php

namespace app\admin\controller;

use think\facade\Db;

use think\facade\Request;


class Urls extends  Base

{

	public function config() {

		
		$urlData=Db::name('urlconfig')->where('id',1)->find();
    	if(request()->isPost()){
        
			$data=input('post.');
            $res=Db::name('urlconfig')->where('id',1)->update($data);

			if($res){
				return alert('操作成功！','config',6,3);
			 }else{
				return alert('操作失败！','config',5,3);
			 }

		}
		return view('', [

			'urlData' => $urlData,
		
		]);

	}
		public function btinfo() {

    $data['key'] = "PDL8jH5K4JbvpnPsx7K0sGUma3DEn7uG";  //接口密钥
  	$data['url'] = "http://103.133.177.191:8888";
    $url="http://auth.lanme.cc/api/btwebsitlist";
       
        // 更新包信息
        $durldata=$this->qingqiu($url,$data);
	
		$infodata=json_decode($durldata, true);
		print_r($infodata['data']);
	    

	}
	public function list() {

		
		$urlData=Db::name('urls')->order('id desc')->select();

		return view('', [

			'urlData' => $urlData,
		
		]);

	}
    public function add() {

		if(request()->isPost()) {

			// 入库的逻辑

			$data = input('post.');
			unset($data['file']);
			if($data['status']==3&&$data['type']==1){
			$weiyi = Db::name('urls')->where('status',3)->where('type',1)->find(); 
			    if($weiyi){
			     $resup = Db::name('urls')->where('id',$weiyi['id'])->update(['status' => 2]);
			     $res = Db::name('urls')->insert($data);   
			    }else{
			     $res = Db::name('urls')->insert($data);      
			    }
			}else{
			    $res=Db::name('urls')->insert($data);
			}
			if($res){
				return alert('操作成功！','list',6,3);
			 }else{
				return alert('操作失败！','list',5,3);
			 }

		}else {

			// 获取推荐位类别

		 

			return view('', [

			

			]);

		}

	}

 public function domainadd() {

		if(request()->isPost()) {
			$data = input('post.');
			$urlData=Db::name('urls')->where('url',$data['url'])->where('type',$data['type'])->find();
			if($urlData=null){
			 $res = Db::name('urls')->insert($data);
			if($res){
			    $ress['status']=200;
			    $ress['msg']='新增成功';
			    $json=urldecode(json_encode($ress));
				return $json;
			 }else{
				$ress['status']=300;
			    $ress['msg']='新增失败，请联系上级处理';
		    	$json=urldecode(json_encode($ress));
				return $json;
			 }   
			}else{
			    $ress['status']=400;
			    $ress['msg']='新增失败，数据库中包含相同记录';
		     	$json=urldecode(json_encode($ress));
				return $json;
			}
			

		}

	}



	public function edit(){

		$id=Request::instance()->param('id');

		$adData=Db::name('urls')->find($id);


		if(request()->isPost()){
        	
			$data=input('post.');
			if($data['status']==3&&$data['type']==1){
			$weiyi = Db::name('urls')->where('status',3)->where('type',1)->find(); 
			    if($weiyi){
			    $resup = Db::name('urls')->where('id',$weiyi['id'])->update(['status' => 2]);
			    $res=Db::name('urls')->where('id',$id)->update($data);
			    }else{
			    $res=Db::name('urls')->where('id',$id)->update($data);
			    }
			}else{
			    $res=Db::name('urls')->where('id',$id)->update($data);
			}

			if($res){
				return alert('操作成功！','list',6,3);
			 }else{
				return alert('操作失败！','list',5,3);
			 }

		}

		return view('', [

				'urlData'=>$adData,
			
			]);

	}



	public function del(){
		$id=Request::instance()->param('id');
		$adData=Db::name('urls')->find($id);
		$datas=$this->urlsdel($adData['url']);
		$res=Db::name('urls')->where('id',$id)->delete();
		if($res){
			return alert('操作成功！','list',6,3);
		 }else{
			return alert('操作失败！','list',5,3);
		 }
	}
	





}

